# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=kmod
pkgver=33
pkgrel=2
pkgdesc="Linux kernel module management utilities"
url="http://git.kernel.org/?p=utils/kernel/kmod/kmod.git;a=summary"
arch="all"
options="!check"  # https://bugs.gentoo.org/408915#c3
license="GPL-2.0-or-later"
# gnu sed is needed for symlink
makedepends_build="scdoc libxslt sed"
makedepends_host="$depends_dev zlib-dev xz-dev zstd-dev openssl-dev>3"
makedepends="$makedepends_build $makedepends_host"
triggers="$pkgname.trigger=/lib/modules/*:/usr/lib/modules/*"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-libs
	$pkgname-bash-completion
	"
source="https://kernel.org/pub/linux/utils/kernel/kmod/kmod-$pkgver.tar.xz
	strndupa.patch
	"

build() {
	if [ -z "$BOOTSTRAP" ]; then
		export CFLAGS="$CFLAGS -flto=auto"
	fi
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--bindir=/bin \
		--sysconfdir=/etc \
		--with-zlib \
		--with-xz \
		--with-zstd \
		--with-openssl
	make
}

package() {
	make DESTDIR="$pkgdir" install
	local i
	mkdir -p "$pkgdir"/sbin
	for i in lsmod rmmod insmod modinfo modprobe depmod; do
		ln -sf ../bin/$i "$pkgdir"/sbin/$i
	done
}

libs() {
	license="LGPL-2.1-or-later"
	default_libs
}

sha512sums="
32d79d0bb7e89012f18458d4e88325f8e19a7dba6e1d5cff01aec3e618d1757b0f7c119735bf38d02e0d056a14273fd7522fca7c61a4d12a3ea5854bb662fff8  kmod-33.tar.xz
2f8edc669fe1de8d92ed88ec37de44454f144631651c46c6b907597c7c3c298f2d3098b83544288baa72226b09d4b0946c056e802488289d2739773a21cd8b81  strndupa.patch
"
